In [ ]:
from IPython.html import widgets
from IPython.display import display
from d3networkx import ForceDirectedGraph, EventfulGraph, empty_eventfulgraph_hook

Hook into the random_graphs NetworkX code.


In [ ]:
from networkx.generators import random_graphs
from networkx.generators import classic

# Add a listener to the eventful graph's construction method.
# If an eventful graph is created, build and show a widget
# for the graph.
def handle_graph(graph):
    print(graph.graph._sleep)
    graph_widget = ForceDirectedGraph(graph)
    display(graph_widget)
EventfulGraph.on_constructed(handle_graph)

# Replace the empty graph of the networkx classic module with
# the eventful graph type.
random_graphs.empty_graph = empty_eventfulgraph_hook(sleep=0.2)

Barabasi Albert


In [ ]:
random_graphs.barabasi_albert_graph(15, 1)

In [ ]:
random_graphs.barabasi_albert_graph(15, 2)

In [ ]:
random_graphs.barabasi_albert_graph(10, 5)

Newman Watts Strogatz


In [ ]:
random_graphs.newman_watts_strogatz_graph(15, 3, 0.25)

Barbell


In [ ]:
classic.barbell_graph(5,0,create_using=EventfulGraph(sleep=0.1))

Circular Ladder


In [ ]:
classic.circular_ladder_graph(5,create_using=EventfulGraph(sleep=0.1))

In [ ]:
classic.circular_ladder_graph(10,create_using=EventfulGraph(sleep=0.1))

Ladder


In [ ]:
classic.ladder_graph(10,create_using=EventfulGraph(sleep=0.1))

Star


In [ ]:
classic.star_graph(10,create_using=EventfulGraph(sleep=0.1))